$(document).ready(function() {
	var userId = $(".userId").text(); //用户ID
	var pagesize = $(".pagesize").text(); //每页记录数
	var contextPath = $(".commonUrl").text(); //绝对路径

	//---------------------------------分页----------------------------------------------

	var pages = $(".pages").text(); //页数
	var pageIndex = $(".pageIndex").text(); //当前页码
	var hasNext = $(".hasNext").text(); //是否有下一页(boolen)
	if (pages == 1) {
		$(".prev,.next").css("cursor", "default");
		$(".prev,.next").css("color", "rgb(166, 166, 166)");
		$(".prev,.next").attr("href", "javascript:void(0)");
	} else {
		if (hasNext == "false") {
			$(".next").css("cursor", "default");
			$(".next").css("color", "rgb(166, 166, 166)");
			$(".next").attr("href", "javascript:void(0)");
		}
		if (pageIndex == 1) {
			$(".prev").css("cursor", "default");
			$(".prev").css("color", "rgb(166, 166, 166)");
			$(".prev").attr("href", "javascript:void(0)");
		}
	}
	for (var i = 1; i < pages;) {
		var result = "";
		i = i + 1;
		result += "<option" + " value=" + "'" + i + "'" + " >" + "第" + i + "页" + "</option>";
		$(".pageNum").append(result);
	}
	$(".pageNum option[value=" + pageIndex + "]").attr("selected", true);

	//----------------------------------异步刷新---------------------------------------------

	$(".pageNum").change(function() {
		var selectedPageNum = $(".pageNum").val(); //选中页码
		var selfUrl = $(".selfUrl").text(); //请求action
		var ajax_url = contextPath + selfUrl;
		$.ajax({
			url: ajax_url,
			data: "user_id=" + userId + "&pageindex=" + selectedPageNum + "&pageSize=" + 3,
			success: function(data) {
				alert("评论成功！");
				var a = eval("(" + data + ")");
				$(".tech-news-grids").empty();
				$.each(a, function(n, commentVal) {
					var result = "";
					result += "<div class='tech-news-grid span_66'>";
					result += commentVal.user_id;
					result += "<p>" + commentVal.content + "</p>";
					result += "</div>";
					$(".tech-news-grids").append(result);
				})
				$(".pageNum option[value=" + pageIndex + "]").attr("selected", true);
			}
		})
	})
})